package biz.impl;

import java.util.Iterator;
import java.util.List;

import dao.EmployeeDAO;
import dao.impl.EmployeeDAOImpl;

import bean.Employee;
import biz.EmployeeBiz;

public class EmployeeBizImpl implements EmployeeBiz {
	EmployeeDAO empDao = new EmployeeDAOImpl();

	public Employee login(String userName, String password) {
		Employee emp = null;
		List<Employee> list = empDao.findEmployeeByProperty("username",	userName);
		Iterator<Employee> it = list.iterator();
		if (it.hasNext()) {
			emp = it.next();
			if (!password.equals(emp.getPassword())) {
				return null;
			}
		}
		return emp;
	}

	public boolean addEmployee(Employee employee) {
		// TODO Auto-generated method stub
		try {
			empDao.save(employee);
			return true;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			return false;
		}
	}

	public boolean delEmployee(short eid) {
		// TODO Auto-generated method stub
		try {
			empDao.delete(eid);
			return true;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			return false;
		}
	}

	public boolean updateEmployee(Employee employee) {
		// TODO Auto-generated method stub
		try {
			empDao.update(employee);
			return true;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			return false;
		}
	}

	public List<Employee> getAll() {
		// TODO Auto-generated method stub
		List<Employee> list = empDao.findAll();
		return list;
	}

	public Employee getEmployeeByuserName(String userName) {
		// TODO Auto-generated method stub
		return (Employee) empDao.findEmployeeByuserName(userName);
	}

	public boolean delEmployee(int eid) {
		// TODO Auto-generated method stub
		return false;
	}

	public Employee getEmployeeByeid(int eid) {
		// TODO Auto-generated method stub
		Employee emp = empDao.findById(eid);
		return emp;
	}

}
